package nicolasb1.additifs;

import java.util.Locale;

import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

public class Preferences extends PreferenceActivity {
	SharedPreferences preferences;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
        // Initialize preferences
		preferences = PreferenceManager.getDefaultSharedPreferences(this);
		String langue = preferences.getString("lang", "auto");
		String locale = "";
		if(langue.compareTo("auto")==0)
		{
			locale = this.getResources().getConfiguration().locale.getDisplayName();
			locale = locale.substring(0, 2);
			if(locale.compareTo("Fr")==0)
			{
				langue = "fr";
			}
			else
			{
				if(locale.compareTo("fr")==0)
				{
					langue = "fr";
				}
				else
				{
					langue = "en";
				}
			}
		}
	    String languageToLoad = langue;
	    Locale locale2 = new Locale(languageToLoad);
	    Locale.setDefault(locale2);
	    Configuration config = new Configuration();
	    config.locale = locale2;
	    getBaseContext().getResources().updateConfiguration(config,
	    getBaseContext().getResources().getDisplayMetrics());
    	addPreferencesFromResource(R.xml.prefs);
    }
	
}
